<?php
namespace app\admin\controller;
use app\common\controller\AdminBase;
/*员工管理*/
class UploaderFile extends AdminBase{
	function _initialize() {
		parent::_initialize();  
    }
	/*文件上传*/
	function upload(){
		sp_file_upload("upload");
	}
	/*文件删除*/	
	function delete(){
		if(isset($_POST['file'])){
			$dir=input('dir',"upload");
		    $file = "./data/$dir/".date("Ymd")."/" . $_POST['file'];
			$flag=FALSE;
		    if(file_exists($file)){
		      $flag= unlink($file);
		    }
			if($flag){
				$this->ajax_success($file);	
			}else{
				$this->ajax_error($file);
			}
		}
	}


    public function uploadFile()
    {
        $filename = 'upload_tmp'; //临时文件夹
        $dir = "./data/$filename/" . date("Ymd") . "/";
        if (!is_dir($dir)) {
            mkdir($dir);
        }
        Vendor('uploader.uploader');
        $uploader = new \Uploader();
        $data = $uploader->upload($_FILES['files'], array(
            'limit' => 1, //Maximum Limit of files. {null, Number}
            'maxSize' => 10, //Maximum Size of files {null, Number(in MB's)}
            'extensions' => array('jpg', 'png', 'jpeg'), //Whitelist for file extension. {null, Array(ex: array('jpg', 'png'))}
            'required' => false, //Minimum one file is required for upload {Boolean}
            'uploadDir' => $dir, //Upload directory {String}
            'title' => array('auto'), //New file name {null, String, Array} *please read documentation in README.md
            'removeFiles' => true, //Enable file exclusion {Boolean(extra for jQuery.filer), String($_POST field name containing json data with file names)}
            'perms' => null, //Uploaded file permisions {null, Number}
            'onCheck' => null, //A callback function name to be called by checking a file for errors (must return an array) | ($file) | Callback
            'onError' => null, //A callback function name to be called if an error occured (must return an array) | ($errors, $file) | Callback
            'onSuccess' => null, //A callback function name to be called if all files were successfully uploaded | ($files, $metas) | Callback
            'onUpload' => null, //A callback function name to be called if all files were successfully uploaded (must return an array) | ($file) | Callback
            'onComplete' => null, //A callback function name to be called when upload is complete | ($file) | Callback
            'onRemove' => 'onFilesRemoveCallback' //A callback function name to be called by removing files (must return an array) | ($removed_files) | Callback
        ));
        if($data['isComplete']){
            $files = $data['data'];
//		print_r($files);
            print_r(substr($files['files'][0],1));
            die;
        }

        if($data['hasErrors']){
            $errors = $data['errors'];
            print_r($errors);
            die;
        }
    }
}
